package t10086.Data.Robot;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class RobotQueue implements Serializable{
    private final Map<String,RobotInfo> robots;//机器人队列
    private int updated;

    public  RobotQueue(RobotQueue robotQueue) {
        robots = new HashMap<>(robotQueue.robots);
        updated = robotQueue.updated;
    }
    public void resetUpdated() {
        this.updated = 0;
    }
    public boolean updateFinished() {
        return robots.size()<=updated;
    }
    public void updateNumber(long oldNumber, long newNumber,long number) {
        //用于状态更新
        if(oldNumber<=number&&newNumber>number) {
            this.updated++;
        }
    }
    public void add(String serialNumber,RobotInfo robot,long number) {
        if(robot.getSelfMovingNumber()>number) {
            this.updated++;
        }
        robots.put(serialNumber,robot);
    }
    public void plusOne() {
        this.updated++;
    }
    public void minusOne() {
        this.updated--;
    }
    public void remove(String serialNumber,long number) {
        RobotInfo robotInfo = robots.remove(serialNumber);
        if(robotInfo!=null && robotInfo.getSelfMovingNumber()>number) {
            this.updated--;
        }
    }

    public RobotQueue() {
        robots = new HashMap<>();
        this.updated = 0;
    }
    public void clear(){
        robots.clear();
        updated = 0;
    }
    public Map<String, RobotInfo> getRobots() {
        return robots;
    }

    public int getUpdated() {
        return updated;
    }

    public void setUpdated(int updated) {
        this.updated = updated;
    }

    @Override
    public String toString() {

        return String.format("RobotQueue [robotNum=%d,updatedNum=%d]", robots.size(),updated);
    }

}
